﻿public class Solution {
    public int FindMinArrowShots(int[][] points)
    {
        if (points is null || points.Length == 0) return 0;
    
        int pointNum = 1;
        Array.Sort(points, (int[] x, int[] y) =>
        {
            if (x[0].Equals(y[0])) return x[1].CompareTo(y[1]);
            return x[0].CompareTo(y[0]);
        });
        for (int i = 1; i < points.Length; i++)
        {
            if (points[i][0] > points[i - 1][1])
            {
                pointNum++;
            }
            else
            {
                points[i][1] = Math.Min(points[i][1], points[i - 1][1]);
            }
        }

        return pointNum;
    }

    public static void Main(string[] args)
    {
        int[][] points = [[1, 2], [3, 4], [5, 6], [7, 8]];
        Solution solution = new Solution();
        int res = solution.FindMinArrowShots(points);
        Console.WriteLine(res);
    }
}